module.exports = function ($scope, $state, $stateParams,$resource,$modal,toaster) {
    /* 分页
        * ========================================= */
    $scope.maxSize = 5;             //最多显示多少个按钮
    $scope.bigCurrentPage = 1;      //当前页码
    $scope.itemsPerPage = 10         //每页显示几条
    // $scope.objs = [];
    $scope.getlist = function () {
        var para = {
            pageNo:$scope.bigCurrentPage, 
            pageSize:$scope.itemsPerPage,
            project_name:$scope.project_name,
            company_name:$scope.company_name
        };
        // para = angular.extend($scope.parameters, para);
        $resource('/api/as/ggc/review/findList', {}, {}).
        save(para,function(res) {
            if (res.errcode !== 0) {
                toaster.error({title:"",body:res.errmsg});
                return;
            }
            $scope.objs = res.data.results;
            $scope.bigTotalItems = res.data.totalRecord;
            $scope.objs.forEach(element => {
              console.log(element.project_code);
              $resource('/api/as/ggc/reviewexpertset/getExpertReview', {}, {}).
              save({'project_code':element.project_code},function(res) {
                  if (res.errcode !== 0) {
                      toaster.error({title:"",body:res.errmsg});
                      return;
                  }
                  console.log(res.data.expert_review);
                  element.review = res.data.expert_review;
              })
              
              $resource('/api/as/ggc/reviewexpertset/getExpertRight', {}, {}).
              save({'project_code':element.project_code},function(res) {
                  if (res.errcode !== 0) {
                      toaster.error({title:"",body:res.errmsg});
                      return;
                  }
                  console.log(res.data.expert_right);
                  element.right = res.data.expert_right;
              })
              
              console.log('~~~~数据');
              console.log(res);
          });
        })
    };
     
    $scope.getlist(); 
    // $scope.search = function(){
    //   k = 0;
    //   h = 0;
    //     var para = {
    //         pageNo:$scope.bigCurrentPage, 
    //         pageSize:$scope.itemsPerPage,
    //         project_name:$scope.project_name,
    //         company_name:$scope.company_name
    //     };
    //     $resource('/api/as/ggc/review/findList', {}, {}).
    //     save(para,function(res) {
    //         if (res.errcode !== 0) {
    //             toaster.error({title:"",body:res.errmsg});
    //             return;
    //         }
    //         console.log(res);
    //         $scope.objs = res.data.results;
    //         $scope.objs.forEach(element => {
    //             $scope.getSearchExpertReview(element.project_code);
    //             $scope.getSearchAvgScore(element.project_code);
    //         });
    //         $scope.bigTotalItems = res.data.totalRecord;
    //         console.log('数据');
    //         console.log($scope.objs);
    //     })
    // }
    $scope.flag = 0;
    var set = '';
    $scope.setexpert = function(project_code){
        set = '1'
        $state.go('app.expert_setting',{'project_code' : project_code,'set' : set});
    }
    $scope.showexpert = function(project_code){
        set = '2'
        $state.go('app.expert_setting',{'project_code' : project_code,'set' : set});
    }
    // 判断专家评审状态
    //项目专家评审
    // $scope.getExpertReview = function(project_code){
    //     $resource('/api/as/ggc/reviewexpertset/getExpertReview', {}, {}).
    //     save({'project_code':project_code},function(res) {
    //         if (res.errcode !== 0) {
    //             toaster.error({title:"",body:res.errmsg});
    //             return;
    //         }
    //         console.log(i);
    //         console.log('review' + res.data.expert_review);
    //         $scope.objs[i].review = res.data.expert_review;
    //         console.log($scope.objs[i]);
    //         i++;
    //     })
    //     // console.log('不带搜索新数据');
    // }
    //项目评分
    // $scope.getAvgScore = function(project_code){
    //     $resource('/api/as/ggc/reviewexpertset/getExpertRight', {}, {}).
    //     save({'project_code':project_code},function(res) {
    //         if (res.errcode !== 0) {
    //             toaster.error({title:"",body:res.errmsg});
    //             return;
    //         }
    //         console.log(j);
    //         console.log('right' + res.data.expert_right);
    //         $scope.objs[j].right = res.data.expert_right;
    //         console.log($scope.objs[j])
    //         j++;
    //     })
    // }
    // $scope.getSearchExpertReview = function(project_code){
    //   $resource('/api/as/ggc/reviewexpertset/getExpertReview', {}, {}).
    //   save({'project_code':project_code},function(res) {
    //       if (res.errcode !== 0) {
    //           toaster.error({title:"",body:res.errmsg});
    //           return;
    //       }
    //       $scope.objs[k].review = res.data.expert_review;
    //       console.log('review' + res.data.expert_review);
    //       k++;
    //   })
    //   console.log('搜索新数据');
    //   console.log($scope.objs);
    // }
    //项目评分
    // $scope.getSearchAvgScore = function(project_code){
    //   $resource('/api/as/ggc/reviewexpertset/getExpertRight', {}, {}).
    //   save({'project_code':project_code},function(res) {
    //       if (res.errcode !== 0) {
    //           toaster.error({title:"",body:res.errmsg});
    //           return;
    //       }
    //       $scope.objs[h].right = res.data.expert_right;
    //       h++;
    //   })
    //   console.log('搜索新数据');
    //   console.log($scope.objs);
    // }

    
};
